package cn.kgc.vue.controller;

import cn.kgc.vue.annotation.LogAnnotation;
import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.commons.ResponseResult;
import cn.kgc.vue.entity.Template;
import cn.kgc.vue.service.TemplateService;
import cn.kgc.vue.vo.TemplateVO;
import cn.kgc.vue.enums.OperationType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;


@RestController
@RequestMapping("resources")
@Api(tags = "资源模块")
public class ResourcesController {
    @Resource
    private TemplateService templateService;

    @PostMapping("resourcesPage")
    @ApiOperation("下载分页模块")
    public ResponseResult resourcesPage(@RequestBody QueryCondition<Template> queryCondition) {
        return templateService.resourcesPage(queryCondition);
    }

    @LogAnnotation(model="资源模块",operation= OperationType.DELETE)
    @DeleteMapping("deleteResources/{id}")
    @ApiOperation("删除资源")
    public ResponseResult deleteResources(@PathVariable("id") String id) {

        return templateService.deleteResources(id);
    }


    @PostMapping("upload")
    @ApiOperation("上传文件流模块")
    public ResponseResult upload(MultipartFile file) {
        return templateService.upload(file);
    }

    @PostMapping("add")
    @ApiOperation("添加资源名称")
    public ResponseResult addResourcesInfo(@RequestBody TemplateVO templateVO) {
        // 文件的名字  文件的大小

        return  templateService.addResourcesInfo(templateVO);
    }


    @GetMapping("download/{uuid}")
    @ApiOperation("下载资源")
    public ResponseResult download(HttpServletResponse response, @PathVariable("uuid") String uuid) {

        return templateService.download(response,uuid);

    }

}
